# Maintainer: Celeste <cielesti@protonmail.com>
maintainer="Celeste <cielesti@protonmail.com>"
pkgname=ocaml-amqp-client
pkgver=2.3.0
pkgrel=0
_pkgreal=amqp-client
pkgdesc="AMQP 0.9.1 client library"
url="https://github.com/andersfugmann/amqp-client"
arch="all !riscv64 !loongarch64" # ocaml
license="BSD-3-Clause"
depends_dev="
	$pkgname=$pkgver-r$pkgrel
	ocaml-lwt-dev
	ocaml-lwt_log-dev
	ocaml-uri-dev
	"
makedepends="
	$depends_dev
	dune
	ocaml
	ocaml-ezxmlm-dev
	"
subpackages="$pkgname-dev"
source="https://github.com/andersfugmann/amqp-client/archive/$pkgver/amqp-client-$pkgver.tar.gz"
builddir="$srcdir/$_pkgreal-$pkgver"

# 32-bit archs
case "$CARCH" in
	arm*|x86) options="$options textrels" ;;
esac

build() {
	dune build --verbose \
		-p amqp-client,amqp-client-lwt
}

check() {
	dune runtest --build-dir=.testenv --verbose \
		-p amqp-client,amqp-client-lwt
}

package() {
	dune install --destdir="$pkgdir" --docdir=/.omit \
		amqp-client amqp-client-lwt
}

dev() {
	default_dev

	cd "$pkgdir"

	local path; find usr/lib/ocaml \( \
			-name '*.cmt' -o \
			-name '*.cmti' -o \
			-name '*.ml' -o \
			-name '*.mli' \
		\) | while read -r path
	do
		amove "$path"
	done
}

prepare_py_provides() {
	local datadir="${subpkgdir:-$pkgdir}"
	local pkgbasedir=${pkgbasedir:-"$startdir/pkg"}
	local controldir="$pkgbasedir"/.control.${subpkgname:-$pkgname}

	options_has "!tracedeps" && return 0

	ocaml4-abuild-find provides \
		"$datadir"/usr/lib/ocaml \
		"$controldir" \
		"$pkgver-r$pkgrel"
}

scan_python3_dependency() {
	local controldir="$2" datadir="$3"

	ocaml4-abuild-find requires \
		"$datadir"/usr/lib/ocaml \
		"$controldir"
}

sha512sums="
921c3f4d0d655dc5caa5c89fe8c4309a6e22d91167676062e0e73f3007b0b5de20e7b461aefdddca6dbdf716d57d90eaefb7e974ae218cce0f0a20fb461c965d  amqp-client-2.3.0.tar.gz
"
